########################
#**********************#
#**                  **#
#  (Global) variables  #
#**                  **#
#**********************#
########################
PROJECT_NAME=kicad-eng-doc
DATE = `date '+%Y%m%d'`


##########################
#  Directories Variables #
##########################
ROOT_DIR=./
CHAPTERS_DIR=chapters/
BUILD_DIR=build/
HTML_BUILD_DIR=$(BUILD_DIR)html/
PDF_BUILD_DIR=$(BUILD_DIR)pdf/
ARCHIVE_DIR=archive/
RELEASE_DIR=release/


#######################
#  Release Variables  #
#######################
RELEASE_NAME=$(PROJECT_NAME)-$(DATE)
TAR_RELEASE=$(RELEASE_NAME).tar.gz
ZIP_RELEASE=$(RELEASE_NAME).zip









#######################
#		      #	
#	Make All      #
#		      #
#######################
all:	cvpcb       \
	eeschema    \
	fileformats \
	kicad	    \
	pcbnew




#########################
#			#
#	Clean All	#
#			#
#########################
clean: cvpcb-clean	 \
       eeschema-clean	 \
       fileformats-clean \
       kicad-clean	 \
       pcbnew-clean




.PHONY: clean









#################################
#				#
#	Kicad Full Build	#
#         			#
#################################
KICADFULL_NAME=kicad-full
KICADFULL_DIR=$(KICADFULL_NAME)/
KICADFULL_TEX=$(KICADFULL_NAME).tex
KICADFULL_PDF=$(KICADFULL_NAME).pdf
KICADFULL_PDF_DIR=$(PDF_BUILD_DIR)$(KICADFULL_NAME)
KICADFULL_HTML=$(KICADFULL_DIR)
KICADFULL_HTML_DIR=$(HTML_BUILD_DIR)$(KICADFULL_DIR)


kicadfull: kicadfull-pdf   \
	   kicadfull-html  \
	   kicadfull-clean \
	   clean


kicadfull-pdf:
		mkdir -p $(BUILD_DIR)
		mkdir -p $(PDF_BUILD_DIR)
		mkdir -p $(KICADFULL_PDF_DIR)
		makeindex $(KICADFULL_TEX)
		latex $(KICADFULL_TEX)
		latex $(KICADFULL_TEX)
		pdflatex $(KICADFULL_TEX)
		mv $(KICADFULL_PDF) $(KICADFULL_PDF_DIR)

kicadfull-html:
		mkdir -p $(BUILD_DIR)
		mkdir -p $(HTML_BUILD_DIR)
		mkdir -p $(KICADFULL_HTML_DIR)
		latex2html $(KICADFULL_TEX)
		mv -f -v $(KICADFULL_HTML) $(HTML_BUILD_DIR)

kicadfull-clean:
		rm $(KICADFULL_NAME).out
		rm $(KICADFULL_NAME).toc
		rm $(KICADFULL_NAME).log
		rm $(KICADFULL_NAME).aux
		rm $(KICADFULL_NAME).idx
		rm $(KICADFULL_NAME).ilg
		rm $(KICADFULL_NAME).ind	



.PHONY: kicadfull-pdf kicadfull-html kicadfull-clean









###########################
#			  #
#	CvPCB Build	  #
#			  #
###########################
CVPCB_NAME=cvpcb
CVPCB_DIR=$(CVPCB_NAME)/
CVPCB_CHAPTER_DIR=$(CHAPTERS_DIR)$(CVPCB_DIR)

cvpcb:	cvpcb-pdf  \
	cvpcb-html \
	cvpcb-clean


cvpcb-pdf:

cvpcb-html:

cvpcb-clean:
		rm $(CVPCB_CHAPTER_DIR)*.aux



.PHONY: cvpcb-pdf cvpcb-html cvpcb-clean









##############################
#			     #
#	EESchema Build       #
#			     #
##############################
EESCHEMA_NAME=eeschema
EESCHEMA_DIR=$(EESCHEMA_NAME)/
EESCHEMA_CHAPTER_DIR=$(CHAPTERS_DIR)$(EESCHEMA_DIR)

eeschema: eeschema-pdf  \
	  eeschema-html \
	  eeschema-clean


eeschema-pdf:

eeschema-html:

eeschema-clean:
		rm $(EESCHEMA_CHAPTER_DIR)*.aux


.PHONY: eeschema-pdf eeschema-html eeschema-clean









##################################
#				 #
#	File Formats Build	 # 
#				 #
##################################
FILEFORMATS_NAME=file_formats
FILEFORMATS_DIR=$(FILEFORMATS_NAME)/
FILEFORMATS_CHAPTER_DIR=$(CHAPTERS_DIR)$(FILEFORMATS_DIR)

fileformats: fileformats-pdf  \
	     fileformats-html \
	     fileformats-clean



fileformats-pdf:

fileformats-html:

fileformats-clean:
		   rm $(FILEFORMATS_CHAPTER_DIR)*.aux



.PHONY: fileformats-pdf fileformats-html fileformats-clean









###############################
#			      #
#	GerbView Build	      #
#			      #
###############################
GERBVIEW_NAME=gerbview
GERBVIEW_DIR=$(GERBVIEW_NAME)/
GERBVIEW_CHAPTER_DIR=$(CHAPTERS_DIR)$(GERBVIEW_DIR)

gerbview: gerbview-pdf gerbview-html gerbview-clean

gerbview-pdf:

gerbview-html:

gerbview-clean:
		rm $(GERBVIEW_CHAPTER_DIR)*.aux


.PHONY: gerbview-pdf gerbview-html gerbview-clean









##########################
#			 #
#	KiCAD Build	 #
#			 #
##########################
KICAD_NAME=kicad
KICAD_DIR=$(KICAD_NAME)/
KICAD_CHAPTER_DIR=$(CHAPTERS_DIR)$(KICAD_DIR)

kicad: kicad-pdf kicad-html kicad-clean

kicad-pdf:

kicad-html:

kicad-clean:
		rm $(KICAD_CHAPTER_DIR)*.aux



.PHONY: kicad-pdf kicad-html kicad-clean









###########################
#			  #
#	PCBNew Build	  #
#			  #
###########################
PCBNEW_NAME=pcbnew
PCBNEW_DIR=$(PCBNEW_NAME)/
PCBNEW_CHAPTER_DIR=$(CHAPTERS_DIR)$(PCBNEW_DIR)

pcbnew: pcbnew-pdf  \
	pcbnew-html \
	pcbnew-clean


pcbnew-pdf:

pcbnew-html:

pcbnew-clean:
		rm $(PCBNEW_CHAPTER_DIR)*.aux



.PHONY: pcbnew-pdf pcbnew-html pcbnew-clean
